package com.spi.soconversion.base.definition;

import java.math.BigDecimal;

import com.spi.soconversion.util.SOCConstants;
import com.spi.soconversion.util.SOCUtility;
import com.spi.soconversion.util.XMLAttributeConstants;
import com.spi.soconversion.util.XMLTagConstants;

public class SOCOrderLineSalvage {

	private String itemID;
	private String itemDesc;
	private String unitOfMeasure;
	private BigDecimal unitPrice;
	private boolean isReturned = false;
	private String status;
	private String lineId;
	private BigDecimal gstTaxPercentage;
	private BigDecimal pstTaxPercentage;
	private BigDecimal hstTaxPercentage;
	private BigDecimal gstTax;
	private BigDecimal pstTax;
	private BigDecimal hstTax;
	private boolean isHSTEligible;
	
	public boolean getIsHSTEligible() {
		return isHSTEligible;
	}

	public void setIsHSTEligible(boolean isHSTEligible) {
		this.isHSTEligible = isHSTEligible;
	}
	
	public String getItemID() {
		return SOCUtility.checkNull(itemID);
	}

	public void setItemID(String itemID) {
		this.itemID = itemID;
	}

	public String getItemDesc() {
		itemDesc= SOCUtility.checkNull(itemDesc);
		if(itemDesc.length()>100)
		{
			itemDesc = itemDesc.substring(0, 100);
		}
		return itemDesc ;
	}

	public void setItemDesc(String itemDesc) {
		this.itemDesc = itemDesc;
	}

	public String getUnitOfMeasure() {
		return SOCUtility.checkNull(unitOfMeasure);
	}

	public void setUnitOfMeasure(String unitOfMeasure) {
		this.unitOfMeasure = unitOfMeasure;
	}
	
	public BigDecimal getUnitPrice() {
		return SOCUtility.checkNumberNull(unitPrice);
	}

	public void setUnitPrice(BigDecimal unitPrice) {
		this.unitPrice = unitPrice;
	}
	
	public void setIsReturned(boolean returnedLine)
	{
		this.isReturned = returnedLine;
	}
	
	public boolean getIsReturned()
	{
		return isReturned;
	}
	
	public String getStatus() {
		return SOCUtility.checkNull(status);
	}

	public void setStatus(String status) {
		this.status = status;
	}
	
	public BigDecimal getPstTaxPercentage() {
		return  SOCUtility.checkNumberNull(pstTaxPercentage);
	}

	public void setPstTaxPercentage(BigDecimal pstTaxPercentage) {
		this.pstTaxPercentage = pstTaxPercentage;
	}
	
	public BigDecimal getGstTaxPercentage() {
		return  SOCUtility.checkNumberNull(gstTaxPercentage);
	}

	public void setGstTaxPercentage(BigDecimal gstTaxPercentage) {
		this.gstTaxPercentage = gstTaxPercentage;
	}
	
	public BigDecimal getHstTaxPercentage() {
		return  SOCUtility.checkNumberNull(hstTaxPercentage);
	}

	public void setHstTaxPercentage(BigDecimal hstTaxPercentage) {
		this.hstTaxPercentage = hstTaxPercentage;
	}
	
	public BigDecimal getPstTax() {
		return  SOCUtility.checkNumberNull(pstTax);
	}

	public void setPstTax(BigDecimal pstTax) {
		this.pstTax = pstTax;
	}
	
	public BigDecimal getGstTax() {
		return  SOCUtility.checkNumberNull(gstTax);
	}

	public void setGstTax(BigDecimal gstTax) {
		this.gstTax = gstTax;
	}
	
	public BigDecimal getHstTax() {
		return  SOCUtility.checkNumberNull(hstTax);
	}

	public void setHstTax(BigDecimal hstTax) {
		this.hstTax = hstTax;
	}
	
	public String getLineId() {
		return lineId;
	}

	public void setLineId(String lineId) {
		this.lineId = lineId;
	}
	
	@Override
	public int hashCode() {
		final int prime = 35;
		int result = 1;
		result = prime * result + ((lineId == null) ? 0 : lineId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SOCOrderLineSalvage other = (SOCOrderLineSalvage) obj;
		if (lineId == null) {
			if (other.lineId != null)
				return false;
		} else if (!lineId.equals(other.lineId))
			return false;
		
		return true;
	}
	
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();

		if(itemID!=null)
		{
			sb.append(XMLTagConstants.START_TAG_ORDER_LINE_OPTIONS);		
			sb.append(SOCConstants.NEW_LINE);
			
			sb.append(XMLTagConstants.START_TAG_ORDER_LINE_OPTION);
			sb.append(SOCConstants.BLANK_STRING);
			
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.OPTION_ITEM_DESC, SOCUtility.replaceXMLSpecialCharacters(getItemDesc())));
			sb.append(SOCConstants.BLANK_STRING);
			
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.OPTION_ITEM_ID,	getItemID()));
			sb.append(SOCConstants.BLANK_STRING);
			
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.OPTION_UNIT_OF_MEASURE, getUnitOfMeasure()));
			sb.append(SOCConstants.BLANK_STRING);
		
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.OPTION_UNIT_PRICE,getUnitPrice().toString()));
			sb.append(SOCConstants.BLANK_STRING);
	
			sb.append(SOCConstants.CLOSING_XML_TAG);
			sb.append(SOCConstants.NEW_LINE);
	
			sb.append(XMLTagConstants.END_TAG_ORDER_LINE_OPTION);
			sb.append(SOCConstants.NEW_LINE);
			sb.append(XMLTagConstants.END_TAG_ORDER_LINE_OPTIONS);
		}

		return sb.toString();

	}
}
